package com.caifu.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * spring工厂对象
 *
 * @author tww
 * ClassName: ApplicationContextUtils.java、
 * createTime: 2020年11月19日 16:58:36
 **/
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextUtils.context = applicationContext;
    }

    /**
     * 根据beanName获取 spring工厂中的对象
     * @param beanName
     * @return
     */
    public static Object getContext(String beanName) {
        return context.getBean(beanName);
    }

}
